/**
 * @file Service.java
 * @create 下午1:51:47
 * @author CX
 * @description 
 */
package cn.edu.hstc.wm.service;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import android.content.Context;

public class FileService {
	Context mContext;

	public FileService(Context context) {
		mContext = context;
	}

	public void write(String fileName, String content) throws IOException {
		FileOutputStream outputStream = mContext.openFileOutput(fileName,
				Context.MODE_PRIVATE); // 以私有方式打开
		outputStream.write(content.getBytes());// 写入流数据
		outputStream.close(); // 关闭流,释放资源
	}

	public String read(String fileName) throws IOException {
		FileInputStream inputStream = mContext.openFileInput(fileName);
		int len = 0;
		byte[] buff = new byte[1024];
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		while ((len = inputStream.read(buff)) != -1) {
			outputStream.write(buff, 0, len); // 写到内存
		}
		byte[] data = outputStream.toByteArray();
		return new String(data);
	}
}
